package com.wang.springbootinit.common;

import cn.hutool.core.util.ObjectUtil;
import com.sun.org.apache.xpath.internal.operations.Bool;
import com.wang.springbootinit.constant.BISystemEnum;
import com.wang.springbootinit.model.result.BIResponseResult;

/**
 * 返回工具类
 */
public class ResultUtils {

    /**
     * 成功
     *
     * @param data
     * @param <T>
     * @return
     */
    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse<>(0, data, "ok");
    }

    public static <T> BaseResponsePage<T> pageSuccess(T data) {
        return new BaseResponsePage<>(0, data, "ok");
    }

    public static Boolean isSuccess(BIResponseResult data) {
        return ObjectUtil.equals(data.getCode(), BISystemEnum.SUCCESS.getCode());
    }

    /**
     * 失败
     *
     * @param errorCode
     * @return
     */
    public static BaseResponse error(ErrorCode errorCode) {
        return new BaseResponse<>(errorCode);
    }
    public static BaseResponsePage pageError(ErrorCode errorCode) {
        return new BaseResponsePage<>(errorCode);
    }

    /**
     * 失败
     *
     * @param code
     * @param message
     * @return
     */
    public static BaseResponse error(int code, String message) {
        return new BaseResponse(code, null, message);
    }

    /**
     * 失败
     *
     * @param errorCode
     * @return
     */
    public static BaseResponse error(ErrorCode errorCode, String message) {
        return new BaseResponse(errorCode.getCode(), null, message);
    }
}
